# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>

pkgname=deepin-daemon
pkgver=6.0.28
pkgrel=1
pkgdesc='Daemon handling the DDE session settings'
arch=('loong64' 'x86_64')
url="https://github.com/linuxdeepin/dde-daemon"
license=('GPL3')
depends=('deepin-desktop-schemas' 'deepin-api' 'deepin-app-services' 'deepin-wloutput-daemon'
         # TODO
         'gtk3' 'libx11' 'gdk-pixbuf-xlib' 'gdk-pixbuf2' 'libxi' 'libpulse' 'glib2' 'libxcursor'
         'libxcrypt' 'libgudev' 'pam' 'iso-codes'
         # accounts
         'accountsservice'
         # accounts/grub
         'deepin-polkit-agent' 'deepin-polkit-agent-ext-gnomekeyring'
         # accounts/keybinding/systeminfo
         'deepin-desktop-base'
         # appearance
         'fontconfig' 'noto-fonts'
         # audio/session
         'pulseaudio' 'alsa-lib'
         # bin/backlight_helper
         'ddcutil'
         # clipboard
         'libxfixes'
         # dock
         'bamf'
         # gesture
         'deepin-widgets'
         # image_effect
         'deepin-session-ui' 'sudo'
         # inputdevices
         'imwheel' 'libxkbfile' 'procps-ng' 'psmisc'
         # iw
         'libnl'
         # keybinding
         'gvfs'
         # keybinding/default-terminal
         'deepin-application-manager'
         # misc
         'librsvg'
         # network
         'mobile-broadband-provider-info' 'org.freedesktop.secrets' 'xdg-utils'
         # network/system
         'systemd' 'systemd-libs'
         # system
         'dmidecode' 'libinput' 'lshw' 'upower'
         # systeminfo
         'lsb-release' 'udisks2' 'util-linux')
makedepends=('sqlite' 'deepin-gettext-tools' 'git' 'mercurial' 'python-gobject' 'networkmanager'
             'bluez' 'go')
optdepends=('networkmanager: for network management support'
            'bluez: for bluetooth support'
            'iw: for miracast module'
            'proxychains-ng: for proxy configuration module')
conflicts=('dde-daemon')
replaces=('dde-daemon')
groups=('deepin')
install="$pkgname.install"
source=("https://github.com/linuxdeepin/dde-daemon/archive/$pkgver/$pkgname-$pkgver.tar.gz"
        $pkgname-fix-vanilla-libinput.patch
        'deepin-daemon.sysusers'
        ddcutil-2.patch)
sha512sums=('d6fa66ace16088e1ab37f5daa37836b0099d75ce0785c7d8c26b58fb5835ff29f609dfae4a8684fa4d8820ae2ef649aee18d662b890707bcf96d721a1efefeba'
            '944b0ae6cf7f613fd00884593c5e5f43aaf0efe4ea7aaa546a06b4367b8da4f2bc486dca640f77743bd1b7b9e4aacf741afe5c5e3ee219c2fdd4cc891ab3d367'
            '808c02d4fec4cbbb01119bbb10499090199e738b7dd72c28a57dde098eef6132723f3434c151f79e21d9f788c7f7bae8046573ac93ba917afe0e803fbffa6d5a'
            '337ac528ff09c32bce2830e6711a7f7a6454c5ce076586057508720414fa2b8414db277d5d6871a6bd2e0d9a00e487c544391d0e56940cc3d1e9677234611e95')

prepare() {
  cd dde-daemon-$pkgver
  patch -p1 -i ../$pkgname-fix-vanilla-libinput.patch
  # Fix build with ddcutils 2
  patch -p1 -i ../ddcutil-2.patch

  # https://github.com/linuxdeepin/developer-center/discussions/3327
  sed -i 's#/usr/libexec#/usr/lib#' keybinding/shortcuts/system_shortcut.go
  sed -i 's#${PREFIX}/libexec/#${PREFIX}/lib/#;s#${DESTDIR}/lib#${DESTDIR}${PREFIX}/lib#' Makefile

  sed -i 's|/etc/os-version|/etc/uos-version|' keybinding/shortcuts/shortcut_manager.go
}

build() {
  cd dde-daemon-$pkgver

  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  
  # make -C network/nm_generator gen-nm-code
  make
}

package() {
  cd dde-daemon-$pkgver
  make DESTDIR="$pkgdir" PAM_MODULE_DIR=usr/lib/security install

  install -Dm644 ../deepin-daemon.sysusers "$pkgdir/usr/lib/sysusers.d/deepin-daemon.conf"
}
